module.exports = (sequelize, Sequelize) => {
  const Post = sequelize.define('post', {
    id: {
      type: Sequelize.INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    title: {
      type: Sequelize.STRING(200),
      allowNull: false,
      validate: {
        notEmpty: true,
        len: [3, 200]
      }
    },
    content: {
      type: Sequelize.TEXT('long'),
      allowNull: false
    },
    summary: {
      type: Sequelize.TEXT,
      allowNull: true
    },
    coverImage: {
      type: Sequelize.STRING(255),
      allowNull: true,
      field: 'cover_image'
    },
    status: {
      type: Sequelize.INTEGER,
      defaultValue: 0
    },
    viewCount: {
      type: Sequelize.INTEGER,
      defaultValue: 0,
      field: 'view_count'
    },
    likeCount: {
      type: Sequelize.INTEGER,
      defaultValue: 0,
      field: 'like_count'
    },
    userId: {
      type: Sequelize.INTEGER,
      allowNull: false,
      references: {
        model: 'users',
        key: 'id'
      },
      field: 'user_id'
    },
    publishedAt: {
      type: Sequelize.DATE,
      allowNull: true,
      field: 'published_at'
    }
  }, {
    timestamps: true,
    paranoid: true, // 软删除
    underscored: true,
    indexes: [
      {
        fields: ['user_id']
      },
      {
        fields: ['status']
      }
    ]
  });

  return Post;
};